package com.ttt.adbgui.function;

import com.ttt.adbgui.gui.GUIMonkey;
import com.ttt.adbgui.jcomp.JFrameComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

@Component
@Slf4j
public class SelectComponent {

    @Autowired
    private ReplaceComponent replaceComponent;
    @Autowired
    private JFrameComponent component;
    @Autowired
    private DocumentList documentList;
    @Autowired
    private TableFill tableFill;
    @Autowired
    private GUIMonkey guiMonkey;
    private JLabel label;

    public void touch(JLabel jLabel) {
        switch (jLabel.getText()) {
            case "快捷操作":
                label = jLabel;
                clickBackground();
                // visible false
                replaceComponent.setVisibleFalse();
                // show
                component.getTable().setVisible(true);
                component.getTextPane().setVisible(true);
                component.getJScrollPane().setVisible(true);
                break;
            case "文件管理":
                label = jLabel;
                clickBackground();
                // visible false
                replaceComponent.setVisibleFalse();
                // show
                component.getTableFile().setVisible(true);
                component.getJScrollPaneFile().setVisible(true);
                // 获取文件列表 并 向表格填充数据
                ArrayList homeList = documentList.getHomeList();
                JTable table = component.getTableFile();
                tableFill.tableDataFile(table,homeList);
                break;
            case "性能监控":
                /*
                * label = jLabel;
                clickBackground();
                replaceComponent.setVisibleFalse();
                // component.getEditorPane().setVisible(true);
                component.getJScrollEditorPane().setVisible(true);
                String htmlUrl = env.getProperty("htmlUrl.page");
                component.getBrowser().navigation().loadUrl(htmlUrl);
                * */
                log.info("(jx试用已过期)");
                break;
            case "ADB Monkey":
                label = jLabel;
                clickBackground();
                // visible
                replaceComponent.setVisibleFalse();
                // show
                guiMonkey.monkeyGui();
                replaceComponent.setRightDesktopPaneTrue();
                break;
            default:
                break;
        }
    }

    public void clickBackground(){
        replaceComponent.setLeftPanelFalse();
        label.setBackground(Color.green);
    }
}
